package com.currency.controller;

import com.currency.exception.AppException;
import com.currency.pojo.WytCurrencyBankcardInfoPojo;
import com.currency.request.BindOilCardRequest;
import com.currency.request.ThirdBindRequest;
import com.currency.response.BaseResponse;
import com.currency.response.QueryAccountResponse;
import com.currency.service.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/account")
@Api(value = "AccountController", tags = {"账户信息接口"})
public class AccountController {
    @Autowired
    AccountService accountService;


    @GetMapping("/query-arrears")
    @ApiOperation(value = "查询用户上月欠款是否已经结清")
    public BaseResponse queryArrears(String userId) {
        return accountService.queryArrears(userId);
    }

    @GetMapping("/repay-arrears")
    @ApiOperation(value = "还清欠款")
    public BaseResponse repayArrears(String userId) throws AppException {
        return accountService.repayArrears(userId);
    }


    @GetMapping("/query")
    @ApiOperation(value = "查询、新建账户信息")
    public QueryAccountResponse query(String userId) throws AppException {
        return accountService.query(userId);
    }

    @PostMapping(value = "/third-bind")
    @ApiOperation(value = "第三方绑定接口")
    public BaseResponse thirdBind(@RequestBody ThirdBindRequest request) throws AppException {
        return accountService.thirdBind(request);
    }

    @PostMapping(value = "/bindOilCard")
    @ApiOperation(value = "油卡绑定，更新")
    public BaseResponse bindOilCard(@RequestBody BindOilCardRequest request) throws AppException {
        return accountService.bindOilCard(request);
    }

    @PostMapping(value = "unbindOilCard")
    @ApiOperation(value = "解绑油卡")
    public BaseResponse unbindOilCard(@RequestBody BindOilCardRequest request) throws AppException {
        return accountService.unbindOilCard(request);
    }

    @RequestMapping(value = "/bind", method = RequestMethod.POST)
    @ApiOperation(value = "卡片绑定或者解绑，通过 bindStatus的值来判定")
    public BaseResponse bindCard(@RequestBody WytCurrencyBankcardInfoPojo request) throws AppException {
        return accountService.bindCard(request);
    }

    @RequestMapping(value = "/update-card", method = RequestMethod.POST)
    @ApiOperation(value = "卡片信息更新，默认卡切换")
    public BaseResponse updateCard(@RequestBody WytCurrencyBankcardInfoPojo request) throws AppException {
        return accountService.updateCard(request);
    }


    @RequestMapping(value = "/exchange", method = RequestMethod.POST)
    @ApiOperation(value = "金币转账交易")
    public BaseResponse exchangeCoins() {
        return new BaseResponse("cey9999", "暂未开通直接转账");
    }

}
